package com.ulrica.morning.service.impl;

import com.ulrica.morning.dao.PoetryInfoDao;
import com.ulrica.morning.dto.PoetryDTO;
import com.ulrica.morning.entity.PoetryInfo;
import com.ulrica.morning.service.PoetryInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 诗词信息表(PoetryInfo)表服务实现类
 *
 * @author LK
 * @since 2022-04-25 19:05:48
 */
@Service("poetryInfoService")
public class PoetryInfoServiceImpl implements PoetryInfoService {
    @Resource
    private PoetryInfoDao poetryInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PoetryInfo queryById(Long id) {
        return this.poetryInfoDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<PoetryInfo> queryAllByLimit(int offset, int limit) {
        return this.poetryInfoDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param poetryInfo 实例对象
     * @return 实例对象
     */
    @Override
    public PoetryInfo insert(PoetryInfo poetryInfo) {
        this.poetryInfoDao.insert(poetryInfo);
        return poetryInfo;
    }

    /**
     * 修改数据
     *
     * @param poetryInfo 实例对象
     * @return 实例对象
     */
    @Override
    public PoetryInfo update(PoetryInfo poetryInfo) {
        this.poetryInfoDao.update(poetryInfo);
        return this.queryById(poetryInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.poetryInfoDao.deleteById(id) > 0;
    }

    @Override
    public List<PoetryDTO> queryList(Integer start, Integer length) {
        if (Objects.nonNull(start) && Objects.nonNull(length)) {
            start = start * length;
        }
        return poetryInfoDao.queryList(start, length);
    }
}